<?php
session_start();
    if(!isset($_SESSION['pwd']) || empty($_SESSION['pwd']))
    {
        header("Location: login.php"); 
        exit;
    }
if(isset($_REQUEST['onsub'])){
    if( $_REQUEST['onsub']=='ok')
    {
          //require_once dirname(__FILE__) . '/../includes/common.inc.php';
          require_once dirname(__FILE__) . '/../includes/data.cfg.php';  
    	  require_once dirname(__FILE__) . '/../includes/pdoorm.inc.php';
        
          $export_name = BRANCH.$_REQUEST['begin_date'].'--'.$_REQUEST['end_date'].'Order';
          header("Content-type:application/vnd.ms-excel");
          header("Content-Disposition:attachment;filename=$export_name.xls");
        
        
          //require_once dirname(__FILE__) . '/includes/pdoorm.inc.php';
          
          
          $sql="SELECT a.criqi,a.customerid,a.price,IFNULL(b.yifu,0) AS yifu,a.type FROM
(
SELECT LEFT(FROM_UNIXTIME(createdDate),10) AS criqi,customerid,price,type,e_oid FROM ns_v1myorder AS d WHERE d.disposalstatus = 0 AND LEFT(FROM_UNIXTIME(createdDate),10) BETWEEN '".$_REQUEST['begin_date']."' and '".$_REQUEST['end_date']."' ORDER BY e_oid ASC)
 AS a
LEFT JOIN 


(
SELECT SUM(amount) AS yifu,orderId FROM ns_v1payment WHERE cancelled = 0  GROUP BY orderId) AS b
ON
a.e_oid = b.orderid";
          $dataarr = getall($sql,1);
          echo"<table border='1'><tr>";
          echo " <td colspan='5' height='30px' align='center'><h3>".$export_name."</h3></td></tr><tr height='27' style='font-weight:bold;'>";
          echo   "<td>Customer Date</td>";
          echo   "<td>Customer #</td>";
          echo   "<td>Total Price</td>";
          echo   "<td>Total Paid</td>";
          echo   "<td>Type</td>";
          echo  "</tr>";  
        
          if(is_array($dataarr))
          {
            foreach ($dataarr as $dr)
            {
               echo" <tr>";        
               echo   "<td>".$dr['criqi']."</td>";
               echo   "<td>".$dr['customerid']."</td>";
               echo   "<td>".$dr['price']."</td>";
               echo   "<td>".$dr['yifu']."</td>";
               echo   "<td>".$dr['type']."</td>";
               echo  "</tr>";      
            }
          }
          echo"</table>";
          die;
    }

}
include 'header.php';
?>
 <br>
 <div>
    <fieldset>
    <legend>Order Amount</legend>
      <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
        <label><span style="color:red;font-weight:bolder;">Date format:2010-01-01</span></label><br>
        <label>P/Date<input type="text" name ="begin_date" id="begin_date"></label><label> TO <input type="text" name ="end_date" id="end_date"></label>
        <label><input type="hidden" name="onsub" id="onsub"  value="ok">
        <input type="submit" value="download"></label>
      </form>
    </fieldset>
 </div>